#region [file: TelefoneDAL.cs, author: Lucas Bittencourt]
// File:    TelefoneDAL.cs
// Author:  Lucas Bittencourt
// Created: terça-feira, 25 de outubro de 2011 09:26:29
// Purpose: Defines dao implementation class for class Telefone
#endregion

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using DA_OOMModel;
using DA_OOMModelIDAL;

namespace DA_OOMNHibernateDAL
{
   /// <summary>
   /// Class that implements methods of ITelefoneDAL interface
   /// </summary>
   public class TelefoneDAL : NHibernateDALBase,  ITelefoneDAL 
   {
      #region CRUD methods
      /// <summary>
      /// Get all instances of Telefone
      /// </summary>     
      public List<Telefone> GetTelefoneList()
      {
         return ConvertToGenericList(base.LoadAll(typeof(Telefone)));
      }
      
      /// <summary>
      /// Get the instances of Telefone from index firstResult to index maxResult
      /// </summary>
      public List<Telefone> GetTelefoneList(int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.LoadAll(typeof(Telefone), firstResult, maxResult));
      }

      /// <summary>
      /// Load the instance of Telefone according its primary key instance.
      /// </summary>
      public Telefone Load(TelefonePK telefonePK)
      {
         IList cs = new ArrayList();
         string[] paramNames = new string[] { "TelIdTelefone" };
         object[] values = new object[] { telefonePK.TelIdTelefone };
         for (int i = 0; i < paramNames.Length; i++)
             cs.Add(Expression.Eq(paramNames[i], values[i]));

         IList list = base.FindByCriterions(typeof(Telefone), cs);
         return (((list != null) && (list.Count > 0)) ? (Telefone)list[0] : null);
      }

      /// <summary>
      /// Query the instances of Telefone according its example instance.
      /// </summary>
      public List<Telefone> QueryByExample(Telefone telefone)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Telefone), telefone));
      }

      /// <summary>
      /// Query the instances of Telefone according its example instance from index firstResult to index maxResult
      /// </summary>
      public List<Telefone> QueryByExample(Telefone telefone, int firstResult, int maxResult)
      {
         return ConvertToGenericList(base.QueryByExample(typeof(Telefone), telefone, firstResult, maxResult));
      }
      
      /// <summary>
      /// Insert the instances of Telefone
      /// </summary>
      public void Insert(Telefone telefoneObject)
      {
         base.Save(telefoneObject);
      }
      
      /// <summary>
      /// Update the instances of Telefone
      /// </summary>
      public void Update(Telefone telefoneObject)
      {
         base.Update(telefoneObject);
      }
      
      /// <summary>
      /// Delete the instances of Telefone
      /// </summary>
      public void Delete(Telefone telefoneObject)
      {
         base.Delete(telefoneObject);
      }
      #endregion
      
   
      /// <summary>
      /// Find the instances of Telefone according to its attribute telCdDdd
      /// </summary>
      public List<Telefone> FindByTelCdDdd(string telCdDdd) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("TelCdDdd", telCdDdd));
         return ConvertToGenericList(base.FindByCriterions(typeof(Telefone), cs));
      }
      
      /// <summary>
      /// Find the instances of Telefone according to its attribute telCdDdd, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Telefone> FindByTelCdDdd(string telCdDdd, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("TelCdDdd", telCdDdd));
         return ConvertToGenericList(base.FindByCriterions(typeof(Telefone), cs, firstResult, maxResult));
      }
      
      
      /// <summary>
      /// Find the instances of Telefone according to its attribute telNuTelefone
      /// </summary>
      public List<Telefone> FindByTelNuTelefone(string telNuTelefone) 
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("TelNuTelefone", telNuTelefone));
         return ConvertToGenericList(base.FindByCriterions(typeof(Telefone), cs));
      }
      
      /// <summary>
      /// Find the instances of Telefone according to its attribute telNuTelefone, 
      /// and the result is from index firstResult to  index maxResult
      /// </summary>
      public List<Telefone> FindByTelNuTelefone(string telNuTelefone, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("TelNuTelefone", telNuTelefone));
         return ConvertToGenericList(base.FindByCriterions(typeof(Telefone), cs, firstResult, maxResult));
      }
      
      /// <summary>
      /// Find <Code>Telefone</Code> instances by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <returns>Telefone instance list</returns>
      public List<Telefone> FindByPessoa(Pessoa pessoa)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Telefone), cs));
      }
      
      /// <summary>
      /// Find <Code>Telefone</Code> instances  instances in range firstResult, maxResult by Pessoa
      /// </summary>
      /// <param name="pessoa"/>
      /// <param name="firstResult">first result to return</param>
      /// <param name="maxResult">max result to return</param>
      /// <returns>Telefone instance list</returns>
      public List<Telefone> FindByPessoa(Pessoa pessoa, int firstResult, int maxResult)
      {
         IList cs = new ArrayList();
         cs.Add(Expression.Eq("Pessoa", pessoa));
         return ConvertToGenericList(base.FindByCriterions(typeof(Pessoa), cs, firstResult, maxResult));
      }

      /// <summary>
      /// Convert the IList to the generic List instance.
      /// </summary>
      private List<Telefone> ConvertToGenericList(IList telefones)
      {
         List<Telefone> telefoneList = new List<Telefone>();
         foreach (Telefone telefone in telefones)
         {
             telefoneList.Add(telefone);
         }
         return telefoneList;
      }      
   }
}